<!-- BEGIN PAGE CONTAINER-->
<div class="container-fluid">
<!-- BEGIN PAGE HEADER-->
<div class="row-fluid">
    <div class="span12">
        <!-- BEGIN PAGE TITLE & BREADCRUMB-->
        <h3 class="page-title">
            Quản lý sản phẩm
        </h3>
        <ul class="breadcrumb">
            <li>
                <i class="icon-home"></i>
                <a href="index.html">Trang chủ</a>
                <i class="icon-angle-right"></i>
            </li>
            <li>
                <a href="#">Khách hàng</a>
                <i class="icon-angle-right"></i>
            </li>
            <li><a href="#">Thêm mới sản phẩm</a></li>
        </ul>
        <!-- END PAGE TITLE & BREADCRUMB-->
    </div>
</div>
<!-- END PAGE HEADER-->
<!-- BEGIN PAGE CONTENT-->
<div class="row-fluid">
    <div class="span12">
        <!-- BEGIN EXAMPLE TABLE PORTLET-->
        <div class="portlet box light-grey">
            <div class="portlet-title">
                <h4><i class="icon-plus-sign"></i>Thêm mới sản phẩm</h4>

                <div class="tools">
                    <a href="javascript:;" class="collapse"></a>
                </div>
            </div>
            <div class="portlet-body form">
                <!-- BEGIN FORM-->
                <form action="/admin/products/update/id/<?php echo $model->product_id;?>" method="post" class="horizontal-form">
                    <div class="row-fluid">
                        <div class="span6">
                            <div class="control-group">
                                <label class="control-label" for="firstName">Tên</label>

                                <div class="controls">
                                    <input type="hidden" id="product_id" class="m-wrap span12" placeholder="" name="Products[product_id]" value="<?php echo $model->product_id;?>">
                                    <input type="text" id="firstName" class="m-wrap span12" name="Products[title]" value="<?php echo $model->title;?>" maxlength="45">
                                </div>
                            </div>
                        </div>
                        <!--/span-->
                        <div class="span6">
                            <div class="control-group">
                                <label class="control-label" for="lastName">Kích thước</label>

                                <div class="controls">
                                    <input type="text" id="size" class="m-wrap span12" placeholder="" name="Products[size]" value="<?php echo $model->size;?>" maxlength="45">
                                </div>
                            </div>
                        </div>
                        <!--/span-->
                    </div>
                    <!--/row-->
                    <div class="row-fluid">
                        <div class="span6">
                            <div class="control-group">
                                <label class="control-label" for="firstName">Mã sản phẩm</label>
                                <div class="controls">
                                    <input type="text" id="product_code" class="m-wrap span12" name="Products[product_code]" value="<?php echo $model->product_code;?>" maxlength="45">
                                </div>
                            </div>
                        </div>
                        <!--/span-->
                        <div class="span6">
                            <div class="control-group">
                                <label class="control-label" for="lastName">Nhà sản xuất</label>
                                <div class="controls">
                                    <input type="text" id="manufacturer" class="m-wrap span12" name="Products[manufacturer]" value="<?php echo $model->manufacturer;?>" maxlength="255">
                                </div>
                            </div>
                        </div>
                        <!--/span-->
                    </div>
                    <!--/row-->
                    <div class="row-fluid">
                        <div class="span6">
                            <div class="control-group">
                                <label class="control-label">Trọng lượng</label>

                                <div class="controls">
                                    <input type="text" id="weight" class="m-wrap span12" placeholder="" name="Products[weight]" value="<?php echo $model->weight;?>" maxlength="45">
                                </div>
                            </div>
                        </div>
                        <!--/span-->
                        <div class="span6">
                            <div class="control-group">
                                <label class="control-label">Khung</label>

                                <div class="controls">
                                    <select name="Products[frame_id]" class="m-wrap span12">
                                        <option value="">Vui lòng chọn khung</option>
                                        <option value="">Không có</option>
                                        <?php
                                        $frames = ProductFrame::model()->findAll();
                                        if(!empty($frames)) {
                                            foreach($frames as $frame) {?>
                                                <option <?php if($frame->frame_id == $model->frame_id) echo 'selected=selected';?> value="<?php echo $frame->frame_id;?>"><?php echo $frame->name;?></option>
                                            <?php }
                                        } else { ?>
                                            <option value="">Không có</option>
                                        <?php }
                                        ?>
                                    </select>
                                </div>
                            </div>
                        </div>
                        <!--/span-->
                    </div>
                    <!--/row-->
                    <div class="row-fluid">
                        <div class="span3">
                            <div class="control-group">
                                <label class="control-label" >Giá</label>
                                <div class="controls">
                                    <div class="input-prepend input-append"> <span class="add-on">$</span>
                                        <input style="width:100px" class="m-wrap" type="text" name="Products[price]" value="<?php echo $model->price;?>"  maxlength="10"/>
                                        <span class="add-on">.00</span>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="span3" style="">
                            <div class="control-group">
                                <label class="control-label" >Giá mới</label>
                                <div class="controls">
                                    <div class="input-prepend input-append"> <span class="add-on">$</span>
                                        <input style="width:100px" class="m-wrap" type="text" name="Products[new_price]" value="<?php echo $model->new_price;?>" maxlength="10"/>
                                        <span class="add-on">.00</span>
                                    </div>
                                </div>
                            </div>
                        </div>

                        <div class="span6">
                        </div>
                        <!--/span-->
                        <!--/span-->
                    </div>

                    <!--/row-->
                    <div class="row-fluid">
                        <div class="span6">
                            <div class="control-group">
                                <label class="control-label">Danh mục</label>

                                <div class="controls">
                                    <select name="Products[category_id]" class="m-wrap span12" id="selectCategory">
                                        <option value="">Chọn danh mục</option>
                                        <?php
                                        $categories = Category::model()->findAll('is_submenu = 2');
                                        if($categories){
                                            foreach($categories as $category) {?>
                                                <option <?php if($category->category_id == $model->category_id) echo 'selected=selected';?> value="<?php echo $category->category_id;?>"><?php echo $category->title;?></option>
                                            <?php }
                                        }
                                        ?>
                                    </select>
                                    <script>

                                    </script>
                                </div>
                            </div>
                        </div>
                        <!--/span-->
                        <div class="span6 ">
                            <div class="control-group">
                                <label class="control-label">Danh mục con</label>

                                <div class="controls">
                                    <select name="Products[subId]" class="m-wrap span12 selectSubCategory">
                                        <option value="">Không có danh mục con</option>
                                        <?php $subCategory = Category::model()->findByPk($model->category_id);
                                        if(!empty($subCategory->is_submenu) && $subCategory->is_submenu == 1) {
                                            $categories = Category::model()->findAll('is_submenu = 1');
                                            if($categories){
                                                foreach($categories as $category) {?>
                                                <option <?php if($category->category_id == $model->category_id) echo 'selected=selected';?> value="<?php echo $category->category_id;?>"><?php echo $category->title;?></option>
                                        <?php }
                                            }
                                        }?>
                                    </select>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="row-fluid">
                    	<div class="control-group">
                    		<label class="control-label">Mô tả</label>
                                <div class="controls">
                                    <textarea id="ckeditor" rows="2" name="Products[description]" style="width:97%" class="m-wrap"><?php echo $model->description;?></textarea>
                                </div>
                            </div>
                    </div>
					<div class="row-fluid">
                    	<input type="checkbox" name="Products[stock]" value="1" <?php echo ($model->stock)? 'checked':'';?>><span style="color:#0B9A00"><b>In Stock</b></span>
                    </div>
                    <br />
                    <!--/row-->
                    <div class="form-actions">
                        <button type="submit" class="btn blue"><i class="icon-ok"></i> Lưu</button>
                        <button type="button" onclick="window.location='/admin/products/admin'" class="btn">Hủy</button>
                    </div>
                </form>
                <!-- END FORM-->
            </div>
        </div>
        <!-- END EXAMPLE TABLE PORTLET-->
    </div>
</div>


<div class="row-fluid">
    <div class="span12">
        <!-- BEGIN EXAMPLE TABLE PORTLET-->
        <?php if(!empty($model->product_id)) {?>
            <div class="portlet box blue">
                <div class="portlet-title">
                    <h4><i class="icon-plus-sign"></i>Tải ảnh cho sản phẩm</h4>

                    <div class="tools">
                        <a href="javascript:;" class="collapse"></a>
                    </div>
                </div>
                <div class="portlet-body form">
                    <!-- BEGIN PAGE CONTENT-->
                    <div class="row-fluid">
                        <div class="span6">
                            <!-- The file upload form used as target for the file upload widget -->
                            <form id="fileupload" action="/admin/products/create" method="POST"
                                  enctype="multipart/form-data">
                                <?php
                                $this->widget('ext.EAjaxUpload.EAjaxUpload',
                                    array(
                                        'id'=>'uploadFile',
                                        'config'=>array(
                                            'action'=>Yii::app()->createUrl('site/upload/id/'.$model->product_id),
                                            'allowedExtensions'=>array("jpg","jpeg","gif","png"),//array("jpg","jpeg","gif","exe","mov" and etc...
                                            'sizeLimit'=>3*1024*1024,// maximum file size in bytes
                                            'minSizeLimit'=>1*1024,
                                            'auto'=>true,
                                            'multiple' => true,
                                            'onComplete'=>"js:function(id, fileName, responseJSON){}",
                                            'messages'=>array(
                                                'typeError'=>"{file} has invalid extension. Only {extensions} are allowed.",
                                                'sizeError'=>"{file} is too large, maximum file size is {sizeLimit}.",
                                                'minSizeError'=>"{file} is too small, minimum file size is {minSizeLimit}.",
                                                'emptyError'=>"{file} is empty, please select files again without it.",
                                                'onLeave'=>"The files are being uploaded, if you leave now the upload will be cancelled."
                                            ),
                                            'showMessage'=>"js:function(message){ alert(message); }"
                                        )

                                    ));
                                ?>
                                <br>
                            </form>
                            <br>

                            <div class="well">
                                <ul>
                                    <li>Dung lượng file tải lên tối đa là <strong>5 MB</strong></li>
                                    <li>Những file hình ảnh này (<strong>JPG, GIF, PNG</strong>) là cho phép.</li>
                                    </li>
                                </ul>
                            </div>
                        </div>
                        <div class="span6">
                        <?php 
                        $imageList = Image::model()->findAll('product_id = ' . $model->product_id);
                        if(count($imageList)) :
                        	foreach($imageList as $image):
                        ?>
	                        <div style="width:150px; float:left; padding-left: 5px;position: relative;">
	                        	<img src="/data/upload/products/<?php echo $image['filename'];?>" width="150"/>
                                <a href="javascript:void(0);"><span id="deleteIcon" class="deleteIcon" title="削除" rel="<?php echo $image['id'];?>">Delete</span></a>
                            </div>
                            <?php endforeach;?>
                        <?php endif;?>
                        </div>
                    </div>
                    <!-- END PAGE CONTENT-->
                </div>
            </div>
        <?php }?>
        <!-- END EXAMPLE TABLE PORTLET-->
    </div>
</div>


<!-- END PAGE CONTENT-->
</div>
<!-- END PAGE CONTAINER-->